GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 137f54...278f6d )
by Florian
01:11
created

Markers.handleMarkerCleared   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 10
rs 9.4285
1
/*jslint
2
  indent: 4
3
*/
4
5
/*global
6
  $,
7
  Conversion, Coordinates, Lines, Marker, Storage,
8
  id2alpha, Lang, showAlert, trackMarker, showProjectionDialog
9
*/
10
11
var Markers = {};
12
Markers.m_map = null;
13
Markers.m_markers = null;
14
15
16
Markers.init = function (themap) {
17
    'use strict';
18
19
    this.m_map = themap;
20
    this.m_markers = [];
21
22
    var id;
23
    for (id = 0; id !== 26 * 10; id = id + 1) {
24
        this.m_markers[id] = new Marker(this, id);
25
    }
26
};
27
28
29
Markers.getSize = function () {
30
    'use strict';
31
32
    return this.m_markers.length;
33
};
34
35
36
Markers.isValid = function (id) {
37
    'use strict';
38
39
    return 0 <= id && id < this.m_markers.length;
40
};
41
42
43
Markers.getById = function (id) {
44
    'use strict';
45
46
    if (id < 0 || id >= this.m_markers.length) {
47
        return null;
48
    }
49
50
    return this.m_markers[id];
51
};
52
53
54
Markers.getUsedMarkers = function () {
55
    'use strict';
56
57
    var count = 0;
58
    this.m_markers.map(function (m) {
59
        if (!m.isFree()) {
60
            count = count + 1;
61
        }
62
    });
63
    return count;
64
};
65
66
67
Markers.getFreeMarkers = function () {
68
    'use strict';
69
70
    return this.getSize() - this.getUsedMarkers();
71
};
72
73
74
Markers.getFreeId = function () {
75
    'use strict';
76
77
    var id;
78
    for (id = 0; id < this.m_markers.length; id = id + 1) {
79
        if (this.m_markers[id].isFree()) {
80
            return id;
81
        }
82
    }
83
    return -1;
84
};
85
86
87
Markers.getNextUsedId = function (id) {
88
    'use strict';
89
90
    var i;
91
    for (i = id + 1; i < this.m_markers.length; i = i + 1) {
92
        if (!this.m_markers[i].isFree()) {
93
            return i;
94
        }
95
    }
96
    return -1;
97
};
98
99
100
Markers.removeById = function (id) {
101
    'use strict';
102
103
    if (id >= 0 && id < this.m_markers.length) {
104
        this.m_markers[id].clear();
105
    }
106
};
107
108
109
Markers.deleteAll = function () {
110
    'use strict';
111
112
    this.m_markers.map(
113
        function (m) {
114
            m.clear();
115
        }
116
    );
117
};
118
119
120
Markers.store = function () {
121
    'use strict';
122
123
    var ids = [];
124
    this.m_markers.map(
125
        function (m) {
126
            if (!m.isFree()) {
127
                ids.push(m.getId());
128
            }
129
        }
130
    );
131
    Storage.set('markers', ids.join(":"));
132
};
133
134
135
Markers.toString = function () {
136
    'use strict';
137
138
    var parts = [];
139
    this.m_markers.map(
140
        function (m) {
141
            if (!m.isFree()) {
142
                parts.push(m.toString());
143
            }
144
        }
145
    );
146
    return parts.join("*");
147
};
148
149
150
Markers.toXmlWpts = function () {
151
    'use strict';
152
153
    var id,
154
        data = '';
155
156
    for (id = 0; id < this.m_markers.length; id = id + 1) {
157
        if (!this.m_markers[id].isFree()) {
158
            data += this.m_markers[id].toXmlWpt();
159
            data += '\n';
160
        }
161
    }
162
163
    return data;
164
};
165
166
167
Markers.update = function () {
168
    'use strict';
169
170
    this.m_markers.map(
171
        function (m) {
172
            m.update();
173
        }
174
    );
175
};
176
177
178
Markers.handleMarkerCleared = function () {
179
    'use strict';
180
181
    if (this.getUsedMarkers() === 0) {
182
        $('#btnmarkers2').hide();
183
    }
184
185
    Lines.updateTotalDistance();
186
    this.store();
187
};
188
189
190
Markers.goto = function (id) {
191
    'use strict';
192
193
    trackMarker('goto');
194
195
    var m = this.getById(id);
196
    if (m) {
197
        this.m_map.setCenter(m.getPosition());
198
    }
199
};
200
201
202
Markers.center = function (id) {
203
    'use strict';
204
205
    trackMarker('center');
206
207
    var m = this.getById(id);
208
    if (m) {
209
        m.setPosition(this.m_map.getCenter());
210
    }
211
};
212
213
214
Markers.newMarker = function (coordinates, id, radius, name, color) {
215
    'use strict';
216
217
    radius = Math.max(radius, 0);
218
219
    if (id < 0 || id >= this.getSize() || !this.getById(id).isFree()) {
220
        id = this.getFreeId();
221
        if (id < 0) {
222
            showAlert(
223
                Lang.t("dialog.error"),
224
                Lang.t("dialog.toomanymarkers_error.content").replace(/%1/, Markers.getSize())
225
            );
226
            return null;
227
        }
228
    }
229
230
    var self = this,
231
        marker,
232
        div,
233
        nextid;
234
235
    if (!name) {
236
        name = id2alpha(id);
237
    }
238
    if (!coordinates) {
239
        coordinates = this.m_map.getCenter();
240
    }
241
242
    marker = this.getById(id);
243
    marker.initialize(this.m_map, name, coordinates, radius, color);
244
    div = this.createMarkerDiv(id);
245
246
    nextid = this.getNextUsedId(id);
247
    if (nextid < 0) {
248
        $('#dynMarkerDiv').append(div);
249
    } else {
250
        $(div).insertBefore('#dyn' + nextid);
251
    }
252
253
    $('#dyn' + id + ' > .edit').keydown(function (e) {
254
        if (e.which === 27) {
255
            self.leaveEditMode(id, false);
256
        } else if (e.which === 13) {
257
            self.leaveEditMode(id, true);
258
        }
259
    });
260
261
    $('#btnmarkers2').show();
262
    $('#btnmarkersdelete1').removeAttr('disabled');
263
    $('#btnmarkersdelete2').removeAttr('disabled');
264
265
    marker.update();
266
    this.store();
267
    Lines.updateLinesMarkerAdded();
268
269
    return marker;
270
};
271
272
273
Markers.createMarkerDiv = function (id) {
274
    'use strict';
275
276
    return "<div id=\"dyn" + id + "\">" +
277
            "<table class=\"view\" style=\"width: 100%; vertical-align: middle;\">\n" +
278
            "    <tr>\n" +
279
            "        <td rowspan=\"3\" style=\"vertical-align: top\">\n" +
280
            "            <img class=\"icon\" src=\"\" />\n" +
281
            "        </td>\n" +
282
            "        <td style=\"text-align: center\"><i class=\"fa fa-map-marker\"></i></td>\n" +
283
            "        <td class=\"name\" colspan=\"2\">marker</td>\n" +
284
            "    </tr>\n" +
285
            "    <tr>\n" +
286
            "        <td style=\"text-align: center\"><i class=\"fa fa-globe\"></i></td>\n" +
287
            "        <td class=\"coords\" colspan=\"2\">N 48° 00.123 E 007° 51.456</td>\n" +
288
            "    </tr>\n" +
289
            "    <tr>\n" +
290
            "        <td style=\"text-align: center\"><i class=\"fa fa-circle-o\"></i></td>\n" +
291
            "        <td class=\"radius\">16100 m</td>\n" +
292
            "        <td>\n" +
293
            "            <div class=\"btn-group\" style=\"padding-bottom: 2px; padding-top: 2px; float: right\">\n" +
294
            "            <button class=\"my-button btn btn-mini btn-warning\" data-i18n=\"[title]sidebar.markers.edit_marker\" type=\"button\"  onclick=\"Markers.enterEditMode(" + id + ");\"><i class=\"fa fa-edit\"></i></button>\n" +
295
            "            <button class=\"my-button btn btn-mini btn-danger\" data-i18n=\"[title]sidebar.markers.delete_marker\" type=\"button\" onClick=\"Markers.removeById(" + id + ");\"><i class=\"fa fa-trash-o\"></i></button>\n" +
296
            "            <button class=\"my-button btn btn-mini btn-info\" data-i18n=\"[title]sidebar.markers.move_to\" type=\"button\" onClick=\"Markers.goto(" + id + ");\"><i class=\"fa fa-search\"></i></button>\n" +
297
            "            <button class=\"my-button btn btn-mini btn-warning\" data-i18n=\"[title]sidebar.markers.center\" type=\"button\" onClick=\"Markers.center(" + id + ");\"><i class=\"fa fa-crosshairs\"></i></button>\n" +
298
            "            <button class=\"my-button btn btn-mini btn-success\" data-i18n=\"[title]sidebar.markers.project\" type=\"button\" onClick=\"Markers.projectFromMarker(" + id + ");\"><i class=\"fa fa-location-arrow\"></i></button>\n" +
299
            "            </div>\n" +
300
            "        </td>\n" +
301
            "    </tr>\n" +
302
            "</table>\n" +
303
            "<table class=\"edit\" style=\"display: none; width: 100%; vertical-align: middle;\">\n" +
304
            "    <tr>\n" +
305
            "        <td style=\"text-align: center; vertical-align: middle;\"><i class=\"fa fa-map-marker\"></i>&nbsp;</td>\n" +
306
            "        <td><input data-i18n=\"[title]sidebar.markers.name;[placeholder]sidebar.markers.name_placeholder\" class=\"name form-control input-block-level\" type=\"text\" style=\"margin-bottom: 0px;\" value=\"n/a\" /></td>\n" +
307
            "    </tr>\n" +
308
            "    <tr>\n" +
309
            "        <td style=\"text-align: center; vertical-align: middle;\"><i class=\"fa fa-globe\"></i>&nbsp;</td>\n" +
310
            "        <td><input data-i18n=\"[title]sidebar.markers.coordinates;[placeholder]sidebar.markers.coordinates_placeholder\" class=\"coords form-control input-block-level\" type=\"text\" style=\"margin-bottom: 0px;\" value=\"n/a\" /></td>\n" +
311
            "    </tr>\n" +
312
            "    <tr>\n" +
313
            "        <td style=\"text-align: center; vertical-align: middle;\"><i class=\"fa fa-circle-o\"></i>&nbsp;</td>\n" +
314
            "        <td><input data-i18n=\"[title]sidebar.markers.radius;[placeholder]sidebar.markers.radius_placeholder\" class=\"radius form-control input-block-level\" type=\"text\" style=\"margin-bottom: 0px;\" value=\"n/a\" /></td>\n" +
315
            "    </tr>\n" +
316
            "    <tr>\n" +
317
            "        <td style=\"text-align: center; vertical-align: middle;\"><i class=\"fa fa-paint-brush\"></i>&nbsp;</td>\n" +
318
            "        <td><input data-i18n=\"[title]sidebar.markers.color;[placeholder]sidebar.markers.color_placeholder\" class=\"color form-control input-block-level\" type=\"color\" style=\"margin-bottom: 0px;\" value=\"#FF0000\" /></td>\n" +
319
            "    </tr>\n" +
320
            "    <tr>\n" +
321
            "        <td colspan=\"2\" style=\"text-align: right\">\n" +
322
            "            <button class=\"btn btn-small btn-primary\" type=\"button\" onclick=\"Markers.leaveEditMode(" + id + ", true);\" data-i18n=\"dialog.ok\">OK</button>\n" +
323
            "            <button class=\"btn btn-small\" type=\"button\" onclick=\"Markers.leaveEditMode(" + id + ", false);\" data-i18n=\"dialog.cancel\">CANCEL</button>\n" +
324
            "        </td>\n" +
325
            "    </tr>\n" +
326
            "</table>" +
327
            "</div>";
328
};
329
330
331
Markers.enterEditMode = function (id) {
332
    'use strict';
333
334
    trackMarker('edit');
335
    var m = this.getById(id);
336
    if (!m) {
337
        return;
338
    }
339
340
    $('#dyn' + id + ' > .edit .name').val(m.getName());
341
    $('#dyn' + id + ' > .edit .coords').val(Coordinates.toString(m.getPosition()));
342
    $('#dyn' + id + ' > .edit .radius').val(m.getRadius());
343
    $('#dyn' + id + ' > .edit .color').val('#' + m.m_color);
344
345
    $('#dyn' + id + ' > .view').hide();
346
    $('#dyn' + id + ' > .edit').show();
347
};
348
349
350
Markers.leaveEditMode = function (id, takenew) {
351
    'use strict';
352
353
    if (!takenew) {
354
        $('#dyn' + id + ' > .view').show();
355
        $('#dyn' + id + ' > .edit').hide();
356
        return;
357
    }
358
359
    var m = this.getById(id),
360
        name = $('#dyn' + id + ' > .edit .name').val(),
361
        s_coords = $('#dyn' + id + ' > .edit .coords').val(),
362
        s_radius = $('#dyn' + id + ' > .edit .radius').val(),
363
        s_color = $('#dyn' + id + ' > .edit .color').val(),
364
        coords = Coordinates.fromString(s_coords),
365
        radius = Conversion.getInteger(s_radius, 0, 100000000000),
366
        errors = [];
367
368
    name = name.replace(/[^a-zA-Z0-9\-_]/g, "_");
369
370
    if (!coords) {
371
        errors.push(Lang.t("sidebar.markers.error_badcoordinates").replace(/%1/, s_coords));
372
    }
373
    if (radius === null) {
374
        errors.push(Lang.t("sidebar.markers.error_badradius").replace(/%1/, s_radius));
375
    }
376
    if (!(/#[a-fA-F0-9]{6}$/.test(s_color))) {
377
        errors.push(Lang.t("sidebar.markers.error_badcolor").replace(/%1/, s_color));
378
    }
379
380
    if (errors.length > 0) {
381
        showAlert(Lang.t("dialog.error"), errors.join("<br /><br />"));
382
        return;
383
    }
384
385
    m.setNamePositionRadiusColor(name, coords, radius, s_color.substr(1));
386
387
    $('#dyn' + id + ' > .view').show();
388
    $('#dyn' + id + ' > .edit').hide();
389
390
    Lines.updateLinesMarkerAdded();
391
};
392
393
394
Markers.projectFromMarker = function (id) {
395
    'use strict';
396
397
    trackMarker('project');
398
399
    var mm = Markers.getById(id),
400
        oldpos = mm.getPosition();
401
402
    showProjectionDialog(
403
        function (data1, data2) {
404
            var angle = Conversion.getFloat(data1, 0, 360),
405
                dist = Conversion.getFloat(data2, 0, 100000000000),
406
                newpos,
407
                newmarker;
408
409
            if (angle === null) {
410
                showAlert(
411
                    Lang.t("dialog.error"),
412
                    Lang.t("dialog.projection.error_bad_bearing").replace(/%1/, data1)
413
                );
414
                return;
415
            }
416
417
            if (dist === null) {
418
                showAlert(
419
                    Lang.t("dialog.error"),
420
                    Lang.t("dialog.projection.error_bad_distance").replace(/%1/, data2)
421
                );
422
                return;
423
            }
424
425
            newpos = Coordinates.projection_geodesic(oldpos, angle, dist);
426
            newmarker = Markers.newMarker(newpos, -1, 0, null, "");
427
            if (newmarker) {
428
                showAlert(
429
                    Lang.t("dialog.information"),
430
                    Lang.t("dialog.projection.msg_new_marker").replace(/%1/, newmarker.getAlpha())
431
                );
432
            }
433
        }
434
    );
435
};
436